package com.runrunfast.fxj.mapper;

import com.runrunfast.fxj.entity.SysResources;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 * 权限表 Mapper 接口
 * </p>
 *
 * @author 陈胤训
 * @since 2019-03-12
 */
@Repository
public interface SysResourcesMapper extends BaseMapper<SysResources> {

    List<SysResources> listByUserId(Integer userId);

    @Select("SELECT re.resources_id,re.resources_name,re.parent_id,re.resources_type,re.url,re.permission,re.icon,re.sort" +
            "        FROM sys_resources re" +
            "        LEFT JOIN sys_role_resources rr ON re.resources_id = rr.resources_id " +
            "        LEFT JOIN sys_role  ro ON rr.role_id = ro.sys_role_id  " +
            "        WHERE ro.sys_role_id = #{roleId} " +
            "        ORDER BY re.parent_id ASC, re.sort ASC")
    List<SysResources> getByroleIdResourcesList(Integer roleId);
}
